<table>
<tr><td><?php
$weekday = array(
   1 => 'Monday',
   2 => 'Tuesday',
   3 => 'Wednesday',
   4 => 'Thursday',
   5 => 'Friday',
   6 => 'Saturday',
   7 => 'Sunday'
   );
$weekdayCounter = 1;
while ($weekdayCounter < 8) {
   ?>
   <table style="background-color: white;">
   <tr><th><?php echo($weekday[$weekdayCounter])?></th></tr>
   <tr><td>
   <form action="<?=$_SERVER['PHP_EDIT']?>" method="post">
   Event: <select name="eventtype"><?php
   $evtQuery = mysql_query("SELECT `id`,`name` FROM `event` ORDER BY `id` ASC");
   while($evt = mysql_fetch_array($evtQuery)) {
	   echo('<option value="' . $evt[id] . '">' . trunc($evt[name], 12) . '</option>');
   }
   ?></select>
   <br />
   Time:<input type="text" name="starttime" onblur="if (value == '') {value = 'HH:mm'}" onfocus="if (value == 'HH:mm') {value =''}" value="HH:mm" size="5" maxlength="5" /><br /><small>(24 hour format)</small>
   <br />
   End Time:<input type="text" name="endtime" value="" size="5" maxlength="5" /><small>(optional)</small><br />
   <input type="hidden" name="cat" value="<?=$cat?>" />
   <input type="hidden" name="mode" value="schedadd" />
   <input type="hidden" name="do" value="addEvent" />
   <input type="hidden" name="weekday" value="<?php echo($weekday[$weekdayCounter++]) ?>" />
   <input type="submit" value="Add Event" />
   </form></td>
   </tr>
   <?php
   $trafSchedQuery = mysql_query("SELECT * FROM `schedule` WHERE `weekday`='".$weekdayCounter."' ORDER BY `starttime` ASC") or die (mysql_error());
   while ($trafSched = mysql_fetch_array($trafSchedQuery)) {
      ?>
      <tr><td class="tabular">
	   <?php
	   $event_query = "SELECT `name` FROM `event` WHERE `id`='".mysql_real_escape_string($trafSched['eventtype'])."' LIMIT 1";
	   $event_result = mysql_query($event_query);
	   $assoc_result = mysql_fetch_assoc($event_result);
	   echo ($assoc_result['name']) ?> <a href="?mode=schedadd&do=editEvent&id=<?=$schedule_row[id]?>&cat=<?=$cat?>" title="Edit this scheduled event"><img style="border: 0px;" height="16" width="16" title="Edit this scheduled event" alt="edit" src="./themes/<?=$theme?>/img/edit.png" /></a><a href="?mode=schedadd&do=deleteEvent&id=<?=$schedule_row[id]?>&cat=<?=$cat?>" title="delete this traffic event from the schedule" onclick="return confirm('Do you really want to delete this traffic event from the weekly schedule?')"><img style="border: 0px;" height="16" width="16" title="delete this event from schedule" alt="trash, delete" src="./themes/<?=$theme?>/img/trash.png" /></a><br />
	   <?php echo (date('H:i', strtotime($schedule_row['starttime'])));
	   if ($trafSched['endtime']) echo ('-' . date('H:i', strtotime($trafSched['endtime'])) . ' (' . $trafSched['eventtype']  . ')' );
   }
   ?>
   </td></tr></table></td><td>
   <?php
}
?></td></tr></table>